package com.android.videotest.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.VideoView;

import com.android.htdvideoview.IjkVideoView;
import com.android.videotest.R;
import com.android.videotest.Urls;

import java.util.ArrayList;

public class ijkDemoActivity extends AppCompatActivity {

    public static void start(Context context) {
        Intent starter = new Intent(context, ijkDemoActivity.class);
        context.startActivity(starter);
    }

    private ijkDemoActivity mActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ijk_democtivity);
        mActivity = this;

        ArrayList<Pair<String, View.OnClickListener>> strings = new ArrayList<>();
        strings.add(new Pair<>("AndroidMediaPlayer", v -> IjkPlayerActivity.start(mActivity, "AndroidMediaPlayer")));
        strings.add(new Pair<>("IjkMediaPlayer", v -> IjkPlayerActivity.start(mActivity, "IjkMediaPlayer")));

        ListView listView = findViewById(R.id.listView);
        listView.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return strings.size();
            }

            @Override
            public Object getItem(int position) {
                return strings.get(position);
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                Pair pair = (Pair) getItem(position);
                if (convertView == null) {
                    ViewGroup.MarginLayoutParams marginLayoutParams = new ListView.MarginLayoutParams(-1, -2);
                    marginLayoutParams.setMargins(100, 100, 100, 100);
                    Pair<String, View.OnClickListener> item = (Pair<String, View.OnClickListener>) getItem(position);
                    convertView = new TextView(mActivity);
                    if (item.second == null) {
                        convertView.setPadding(16, 8, 16, 8);
                    } else {
                        convertView.setPadding(30, 30, 30, 30);
                    }
                    convertView.setLayoutParams(marginLayoutParams);
                }
                ((TextView) convertView).setText((String) pair.first);
                convertView.setOnClickListener((View.OnClickListener) pair.second);
                return convertView;
            }
        });
    }


}
